import yaml
import json
import shutil
import os

os.system("rm -rf ./video/*")


with open("./good_video_info.json", 'r') as f:
    val_data = json.load(f)
    f.close()

video_root_dir = "/Users/zhangxiaomin/Works/A05-Developments/CV/cmit_me_inference/res/video"

yaml_data = {}

couts = 0
for key, item in val_data.items():
    # print(key)
    # print(item)
    if item['8s_label_name'] == "others":
        continue
    if key == 'sub23@EP0525f.avi':
        continue
    yaml_data[key] = item
    shutil.copyfile(f"{video_root_dir}/{key}", f"./video/{key}")
    couts += 1
    if couts >= 45:
        break

with open("./video_info.json", 'r') as f:
    all_video_data = json.load(f)
    f.close()

couts = 0
for key, item in all_video_data.items():
    if key == 'sub23@EP0525f.avi':
        continue
    if not yaml_data.__contains__(key):
        yaml_data[key] = item
        shutil.copyfile(f"{video_root_dir}/{key}", f"./video/{key}")
        couts +=1
        if couts >= 9:
            break


f = open("./video/request_video.yaml", 'w')
yaml.safe_dump(yaml_data, f, indent=4)
f.close()

f = open("./request_video.yaml", 'w')
yaml.safe_dump(yaml_data, f, indent=4)
f.close()


# request_video_names = []
# for key, item in yaml_data.items():
#     request_video_names.append(key)

# f = open("./video/request_video_names.txt", 'w')
# for idx, name in enumerate(request_video_names):
#     if idx == len(request_video_names) -1:
#         f.write(name)
#     else:
#         f.write(f"{name}\n")
# f.close()

